home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 9829 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  922 b 

  1. Path: web.cae.ca!usenet
  2. From: fraserh@cae.ca (Fraser Hutchinson)
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: Union equivelant in C++
  5. Date: 4 Mar 1996 18:10:09 GMT
  6. Organization: CAE Electronics Ltd.
  7. Message-ID: <4hfbm1$t53@web.cae.ca>
  8. References: <3130A7A2.404D@bath.ac.uk>
  9. NNTP-Posting-Host: pch63.cae.ca
  10. Mime-Version: 1.0
  11. Content-Type: Text/Plain; charset=US-ASCII
  12. X-Newsreader: WinVN 0.99.7
  13.  
  14. In article <3130A7A2.404D@bath.ac.uk>, ma2rct@bath.ac.uk says...
  15. >
  16. >I need to store a data structure where there is more than one 
  17. >choice for what is stored.
  18. >
  19. >Effectively a structure of unions.
  20. >
  21. >Is there anything better than a union that is C++ specific.
  22.  
  23. Yes, class inheritance and polymorphism.
  24.  
  25. i.e, create a base class for the union, and derive a class for each data 
  26. type you want to handle.  If you provide properly designed virtual 
  27. methods in the base class, you will achieve the result you desire.
  28.  
  29. Regards,
  30.  
  31.  
  32. Fraser
  33.  
  34.  
  35.